<?php
require_once ('checks.php');

	require_once 'Database.php';
	require_once 'Image.php';
	$db = new DB();
	if (isset($_POST['Update'])) {
		
		if (isset($_POST['fldcheckbox'])) {
			$flag="1";
		} else {
			$flag="0";
		}
		
		$img = new Image($_SESSION['img_name'],$_POST['gallery'],$_POST['date'],$flag,$_POST['order']);
		$img->setId($_SESSION['img_id']);
		$db->updateImage($img);
		
	}  else {
		$img = $db->extractImage($_GET['image']);
		$_SESSION['img_name']= $img->getName();
		$_SESSION['img_id']= $img->getId();
		
	}




?>

<form method="post" action="?page=edit_image&image=<?php echo  $img->getName() ?>" enctype="multipart/form-data">
			<table>
				<tr>
					<td colspan="3"><img src='images/gallery/<?php echo $img->getName() ?>' width='140' height='140'><br>
					</td>
				</tr>
				
					<tr>
						<td>Front Page :
						</td>
						<td> 
							<input type="checkbox" name="fldcheckbox" id="fldcheckbox" />
						</td>
					</tr>
					<tr>
						<td>
							Order :
						</td>
						<td>
							<input type="text" name="order" id="order" size="2" value="<?php echo $img->getOrder(); ?>">
						</td>	
					</tr>
					<tr>
						<td> Date :</td>
						<td colspan="2">
							<input type="text" class="tcal" name="date" maxlength="10" value="<?php 
																									if (isset($img)){
																										echo $img->getDate();
																									}												
																								?>">
						</td>
					</tr>
					<tr>
						<td colspan = "3">
							<textarea name="gallery" id="gallery" cols="20" rows="20" >
							<?php 
								if (isset($img)){
									echo $img->getText();
								}												
							?>
						</textarea>
						</td>
					</tr>
				
				<tr>
					
					<td colspan='3' >
					<input type="submit" value="Update" name="Update">
						<input type="button" value="Home"  onclick="location.href='?page=admin_index'">
					</td>				
				</tr>			
			</table>
		</form>